package com.qfedu.dtboot.config;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;


/**
 * @author 水杯 Druid datasource 数据源配置
 * @date 2020-08-05 22:31
 */
@Configuration
public class DruidConfig {
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")//获取配置文件配置信息
    @Qualifier("druidDataSource")
    public DataSource druidDataSource()
    {
        System.out.println("druid datasource");
        DruidDataSource dataSource=new DruidDataSource();
        List<Filter> filters=new ArrayList<Filter>();
        filters.add(wallFilter());
        dataSource.setProxyFilters(filters);

        return  dataSource;
    }
    @Bean
    public WallFilter wallFilter()
    {
        WallFilter wallFilter = new WallFilter();
        WallConfig wallConfig = new WallConfig();
        wallConfig.setMultiStatementAllow(true);
        wallFilter.setConfig(wallConfig);
         return wallFilter;

    }

}
